<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const str = "2023-12-21";
      const r = str.match(/(?<year>\d{4})-(?<month>\d{2})-(?:\d{2})/);

      console.log(r);
    </script>
  </body>
</html>
